package com.xzbd.jflowable.controller;

import java.util.ArrayList;
import java.util.List;

import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xzbd.jflowable.service.TestService;

@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private TestService testService;

    @GetMapping("/tesk")
    public List<String> getTasks(@RequestParam String assignee) {
        List<Task> tasks = testService.getTasks(assignee);
        List<String> res = new ArrayList<>();
        if (tasks == null) {
            return res;
        }
        for (Task t : tasks) {
            res.add(t.getName() + " -- " + t.getAssignee());
        }
        return res;
    }

    @GetMapping("start/process")
    public String getMethodName(@RequestParam String processKey) {
        ProcessInstance startProcess = testService.startProcess(processKey);
        return startProcess.getDeploymentId() + " -- " + startProcess.getName();
    }

}
